import api from '../../api';
import deviceInfo from '@ohos.deviceInfo';
import uuid from '../../../others/uuid';
import systemDateTime from '@ohos.systemDateTime';
import http from '@ohos.net.http';
export default class getFp extends api{
  static async getInstance(){
    let seed_id = uuid()
    let seed_time = (await systemDateTime.getCurrentTime(false)).toString()
    let deviceId = "3f652a5783274d28"//deviceInfo.productSeries+deviceInfo.sdkApiVersion+seed_time
    return new getFp(deviceId,seed_id,seed_time)
  }
  private constructor(deviceId,seed_id,seed_time) {
    super()
    this.url = "https://public-data-api.mihoyo.com/device-fp/api/getFp"
    this.method = http.RequestMethod.POST
    this.body = {
      device_id:deviceId,
      seed_id,
      seed_time,
      platform:"5",
      device_fp:this.getFakeDeviceFp(),
      app_name:"account_cn",
      ext_fields:JSON.stringify(new ext_fields())
    }
  }
  private getFakeDeviceFp(){
    const Random = ()=>{
      return Math.floor(Math.random()*10)+''
    }
    let i = 10
    let str = Random()
    let i2 = 0;
    let i3 = i-2;
    if(i3>=0){
      while(true){
        str+=Random()
        if(i2==i3){
          break;
        }
        i2++;
      }
    }
    return str
  }
}
class ext_fields{
  browserLanguage="zh-CN"
  browserPlat=""
  browserScreenSize=""
  browserTimeZone="Asia/Beijing"
  cpuClass="unknown"
  deviceMemory="4"
  hardwareConcurrency="4"
  hasLiedBrowser=0
  hasLiedOs=0
  hasLiedResolution=1
  ifAdBlock=0
  ifNotTrack="unkown"
  isTouchSupported=true
  listOfPlugins="unknown"
  maxTouchPoints=5
  numOfPlugins=0
  screenRatio=1.75
  userAgent=`Mozilla/5.0 (Linux; Android 7.1.2; SM-N9760 Build/N2G48C; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.198 Safari/537.36 miHoYoBBS/2.40.1`
  webGlRender="Adreno (TM) 640"
  webGlVendor="Qualcomm"

  constructor() {

  }
}